package cn.sibu.plugin.authorize.http;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;

import org.apache.http.Header;

import cn.sibu.plugin.authorize.bean.AgencyListEvent;
import cn.sibu.plugin.authorize.bean.ChangePasswordEvent;
import cn.sibu.plugin.authorize.bean.CheckAgentEvent;
import cn.sibu.plugin.authorize.bean.CheckInviteCodeEvent;
import cn.sibu.plugin.authorize.bean.CheckdeCodeEvent;
import cn.sibu.plugin.authorize.bean.CheckdeMobileWeixinEvent;
import cn.sibu.plugin.authorize.bean.CheckedKeyEvent;
import cn.sibu.plugin.authorize.bean.EditUserperInfoEvent;
import cn.sibu.plugin.authorize.bean.ExistsMobileEvent;
import cn.sibu.plugin.authorize.bean.FeedbackUserEvent;
import cn.sibu.plugin.authorize.bean.GetNewUserEvent;
import cn.sibu.plugin.authorize.bean.InviteCodeEvent;
import cn.sibu.plugin.authorize.bean.InviteCodeListEvent;
import cn.sibu.plugin.authorize.bean.LoginEvent;
import cn.sibu.plugin.authorize.bean.LoginOutEvent;
import cn.sibu.plugin.authorize.bean.LowerAgentListEvent;
import cn.sibu.plugin.authorize.bean.PendingDealerListEvent;
import cn.sibu.plugin.authorize.bean.SearchUserEvent;
import cn.sibu.plugin.authorize.bean.SendDentifyingCodeEvent;
import cn.sibu.plugin.authorize.bean.SetPasswordEvent;
import cn.sibu.plugin.authorize.bean.SetPauseAgentEvent;
import cn.sibu.plugin.authorize.util.L;
import de.greenrobot.event.EventBus;

/**
 * Created by hfl on 2015/5/8.
 */
public class SibuAuthorizeHttp {
    //users
    private static String HTTP_TESTADDRESS = "http://agentapi.sibu.cn/";//user线上地址
    private static String HTTP_LACALTEST = "http://testapi.sibu.cn/";//user测试地址
    private static String HTTP_NOWUSER = HTTP_TESTADDRESS+"%s";//users当前使用地址
    //异步
    private static AsyncHttpClient client =new AsyncHttpClient();
    //审核经销商
    public static void checkAgent(String token,int uid,int touid,int status,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/user?at=ispass");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));
        params.add("touid",String.valueOf(touid));
        params.add("status",String.valueOf(status));
        client.get(context, url, params, new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    CheckAgentEvent checkAgentEvent = JSON.parseObject(s.toString(), CheckAgentEvent.class);
                    EventBus.getDefault().postSticky(checkAgentEvent);
                    System.out.println("审核经销商=" + checkAgentEvent);
                } catch (Exception e) {
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new CheckAgentEvent());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new CheckAgentEvent());
            }


        });
    }
    //待审经销商列表
    public static void pendingDealerList(String token,int uid,int touid,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/user?at=pending");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));
        params.add("touid",String.valueOf(touid));

        client.get(context, url, params, new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    PendingDealerListEvent pendingDealerListEvent = JSON.parseObject(s.toString(), PendingDealerListEvent.class);
                    EventBus.getDefault().postSticky(pendingDealerListEvent);
                    System.out.println("待审经销商列表=" + pendingDealerListEvent);
                } catch (Exception e) {
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new PendingDealerListEvent());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new PendingDealerListEvent());
            }


        });
    }
    //暂停经销商
    public static void setPauseAgent(String token,int uid,int touid,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/user?at=setpause");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));
        params.add("touid",String.valueOf(touid));

        client.get(context, url, params, new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    SetPauseAgentEvent setPauseAgentEvent = JSON.parseObject(s.toString(), SetPauseAgentEvent.class);
                    EventBus.getDefault().postSticky(setPauseAgentEvent);
                    System.out.println("暂停经销商=" + setPauseAgentEvent);
                } catch (Exception e) {
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new SetPauseAgentEvent());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new SetPauseAgentEvent());
            }


        });
    }
    //经销商下级列表
    public static void lowerAgentList(String token,int uid,int touid,int type,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/user?at=nextuser");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));
        params.add("touid",String.valueOf(touid));
        params.add("type",String.valueOf(type));
        client.get(context, url, params, new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    LowerAgentListEvent lowerAgentListEvent = JSON.parseObject(s.toString(), LowerAgentListEvent.class);
                    EventBus.getDefault().postSticky(lowerAgentListEvent);
                    System.out.println("经销商下级列表=" + lowerAgentListEvent);
                } catch (Exception e) {
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new LowerAgentListEvent());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new LowerAgentListEvent());
            }


        });
    }
    //经销商列表
    public static void agencyList(String token,int uid,int type,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/user?at=agency");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));
        params.add("type",String.valueOf(type));
        client.get(context, url, params, new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    AgencyListEvent agencyListEvent= JSON.parseObject(s.toString(), AgencyListEvent.class);
                    EventBus.getDefault().postSticky(agencyListEvent);
                    System.out.println("经销商列表=" + agencyListEvent);
                } catch (Exception e) {
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new AgencyListEvent());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new AgencyListEvent());
            }
        });
    }
    //搜索用户
    public static void searchUser(String token,int uid,String key,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/user?at=serach");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));
        params.add("key",key);

        client.get(context, url, params, new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    SearchUserEvent searchUserEvent = JSON.parseObject(s.toString(), SearchUserEvent.class);
                    EventBus.getDefault().postSticky(searchUserEvent);
                    System.out.println("搜索用户=" + searchUserEvent);
                } catch (Exception e) {
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new SearchUserEvent());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("搜索用户网络连接失败=" + s);
                EventBus.getDefault().postSticky(new SearchUserEvent());
            }


        });
    }
    //获得邀请码
    public static void inviteCode(String token,int uid,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/invitecode?at=add");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));

        client.get(context, url, params, new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    InviteCodeEvent inviteCodeEvent = JSON.parseObject(s.toString(), InviteCodeEvent.class);
                    EventBus.getDefault().postSticky(inviteCodeEvent);
                    System.out.println("获得邀请码=" + inviteCodeEvent);
                } catch (Exception e) {
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new InviteCodeEvent());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new InviteCodeEvent());
            }


        });
    }
    //邀请码列表
    public static void inviteCodeList(String token,int uid,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/invitecode?at=list");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));

        client.post(context, url, params, new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    InviteCodeListEvent inviteCodeListEvent= JSON.parseObject(s.toString(), InviteCodeListEvent.class);
                    EventBus.getDefault().postSticky(inviteCodeListEvent);
                    System.out.println("邀请码列表=" + inviteCodeListEvent);
                } catch (Exception e) {
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new InviteCodeListEvent());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new InviteCodeListEvent());
            }


        });
    }
    //意见反馈
    public static void feedbackUser(String token,int uid,String content,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/feedback?at=add");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));
        params.add("content",content);
        client.post(context, url, params, new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    FeedbackUserEvent feedbackUserEvent= JSON.parseObject(s.toString(), FeedbackUserEvent.class);
                    EventBus.getDefault().postSticky(feedbackUserEvent);
                    System.out.println("意见反馈=" + feedbackUserEvent);
                } catch (Exception e) {
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new FeedbackUserEvent());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new FeedbackUserEvent());
            }


        });
    }
    //登入或注销接口
    public static void loginOut(String token,int uid,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/user?at=logout");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));

        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    LoginOutEvent loginOutEvent= JSON.parseObject(s.toString(), LoginOutEvent.class);
                    EventBus.getDefault().postSticky(loginOutEvent);
                    System.out.println("登入或注销接口=" + loginOutEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new LoginOutEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new LoginOutEvent() );
            }


        });
    }
    //检查 key:微信号，用户名，QQ,邮箱,身份证,旺旺号, 是否存在
    public static void checkedKey(String key,String value,Context context){
        String url = String.format(HTTP_NOWUSER, "public/user?at=exists");
        RequestParams params = new RequestParams();
        params.add("key",key);
        params.add("value",value);

        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    CheckedKeyEvent checkedKeyEvent= JSON.parseObject(s.toString(), CheckedKeyEvent.class);
                    EventBus.getDefault().postSticky(checkedKeyEvent);
                    System.out.println("检查 key:微信号，用户名，QQ,邮箱,身份证,旺旺号, 是否存在=" + checkedKeyEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new CheckedKeyEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new CheckedKeyEvent() );
            }


        });
    }
    //修改用户个人信息
    public static void editUserperInfo(String token,int uid,int touid,String trueName,String identityCard,String weixin,String weixinName,int qq,String email,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/user?at=editinfo");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",String.valueOf(uid));
        params.add("touid",String.valueOf(touid));
        params.add("trueName",trueName);
        params.add("identityCard",identityCard);
        params.add("weixin",weixin);
        params.add("weixinName",weixinName);
        params.add("qq",String.valueOf(qq));
        params.add("email",email);

        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    EditUserperInfoEvent editUserperInfoEvent = JSON.parseObject(s.toString(), EditUserperInfoEvent.class);
                    EventBus.getDefault().postSticky(editUserperInfoEvent);
                    System.out.println("修改用户个人信息=" + editUserperInfoEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new EditUserperInfoEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new EditUserperInfoEvent() );
            }


        });
    }

    //修改密码
    public static void changePassword(String token,String uid,String oldPasswd,String newPasswd,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/user?at=editpasswd");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",uid);
        params.add("oldPasswd",oldPasswd);
        params.add("newPasswd",newPasswd);
        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    ChangePasswordEvent changePasswordEvent = JSON.parseObject(s.toString(), ChangePasswordEvent.class);
                    EventBus.getDefault().postSticky(changePasswordEvent);
                    System.out.println("修改密码=" + changePasswordEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new ChangePasswordEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new ChangePasswordEvent() );
            }


        });
    }

    //获取最新用户信息
    public static void getNewUser(String token,String uid,Context context){
        String url = String.format(HTTP_NOWUSER, "agency/user?at=getuser");
        RequestParams params = new RequestParams();
        params.add("token",token);
        params.add("uid",uid);
        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    GetNewUserEvent getNewUserEvent = JSON.parseObject(s.toString(), GetNewUserEvent.class);
                    EventBus.getDefault().postSticky(getNewUserEvent);
                    System.out.println("获取最新用户信息=" + getNewUserEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new GetNewUserEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new GetNewUserEvent() );
            }


        });
    }

    /*//设置用户基本信息接口
    public static void setUserInfo(int uid,String userName,String trueName,String identityCard,String weixinName,int qq,String email,Context context){
        String url = String.format(HTTP_NOWUSER, "public/user?at=setinfo");
        RequestParams params = new RequestParams();
        params.add("uid",String.valueOf(uid));
        params.add("userName",userName);
        params.add("identityCard",identityCard);
        params.add("weixinName",weixinName);
        params.add("qq",String.valueOf(qq));
        params.add("email",email);
        client.post(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    SetUserInfoEvent setUserInfoEvent = JSON.parseObject(s.toString(), SetUserInfoEvent.class);
                    EventBus.getDefault().postSticky(setUserInfoEvent);
                    System.out.println("设置用户基本信息接口=" + setUserInfoEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new SetUserInfoEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new SetUserInfoEvent());
            }


        });
    }

*/
    //检查手机号是否存在接口
    public static void existsMobile(String mobile,String type,Context context){
        String url = String.format(HTTP_NOWUSER, "public/user?at=existsmobile");
        RequestParams params = new RequestParams();
        params.add("mobile",mobile);
        params.add("type",type);
        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    ExistsMobileEvent existsMobileEvent= JSON.parseObject(s.toString(), ExistsMobileEvent.class);
                    EventBus.getDefault().postSticky(existsMobileEvent);
                    System.out.println("检查手机号是否存在接口=" + existsMobileEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new ExistsMobileEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new ExistsMobileEvent() );
            }


        });
    }

    //检测 手机号 和微信号 是否存在 （每次的微信号和密码都要不一样）
    public static void checkdeMobileWeixin(String uuid,String mobile,String weixin,Context context){
        String url = String.format(HTTP_NOWUSER, "public/user?at=account");
        RequestParams params = new RequestParams();
        params.add("uuid",uuid);
        params.add("mobile",mobile);
        params.add("weixin",weixin);
        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    CheckdeMobileWeixinEvent checkdeMobileWeixinEvent = JSON.parseObject(s.toString(), CheckdeMobileWeixinEvent.class);
                    EventBus.getDefault().postSticky(checkdeMobileWeixinEvent);
                    System.out.println("检测 手机号 和微信号 是否存在=" + checkdeMobileWeixinEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new CheckdeMobileWeixinEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new CheckdeMobileWeixinEvent() );
            }


        });
    }
    //设置密码
    public static void setPassword(String uuid,String mobile,int type,String passwd,Context context){
        String url = String.format(HTTP_NOWUSER, "public/user?at=passwd");
        RequestParams params = new RequestParams();
        params.add("uuid",uuid);
        params.add("mobile",mobile);
        params.add("type",String.valueOf(type));
        params.add("passwd",passwd);
        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    SetPasswordEvent setPasswordEvent  = JSON.parseObject(s.toString(), SetPasswordEvent.class);
                    EventBus.getDefault().postSticky(setPasswordEvent);
                    System.out.println("设置密码=" + setPasswordEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new SetPasswordEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new SetPasswordEvent() );
            }


        });
    }
    // 校验邀请码
    public static void checkInviteCode(String inviteCode,Context context){
        String url = String.format(HTTP_NOWUSER, "public/user?at=code");;
        RequestParams params = new RequestParams();
        params.add("inviteCode",inviteCode);

        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    CheckInviteCodeEvent checkInviteCodeEvent  = JSON.parseObject(s.toString(), CheckInviteCodeEvent.class);
                    EventBus.getDefault().postSticky(checkInviteCodeEvent );
                    System.out.println("校验邀请码=" + checkInviteCodeEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new CheckInviteCodeEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new CheckInviteCodeEvent() );
            }


        });
    }
    // 检查验证码是否正确
    public static void checkCode(String mobile,String type,String code,Context context){
        String url = String.format(HTTP_NOWUSER, "public/user?at=checkcode");;
        RequestParams params = new RequestParams();
        params.add("mobile",mobile);
        params.add("type",type);
        params.add("code",code);
        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    CheckdeCodeEvent checkCodeEvent  = JSON.parseObject(s.toString(), CheckdeCodeEvent.class);
                    EventBus.getDefault().postSticky(checkCodeEvent);
                    System.out.println("检查验证码是否正确=" + checkCodeEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new CheckdeCodeEvent());
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new CheckdeCodeEvent());
            }


        });
    }
    // 发送验证码
    public static void sendDentifyingCode(String mobile,String type,Context context){
        String url = String.format(HTTP_NOWUSER, "public/user?at=sendsms");;
        RequestParams params = new RequestParams();
        params.add("mobile",mobile);
        params.add("type",type);

        client.get(context,url,params,new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    SendDentifyingCodeEvent sendDentifyingCodeEvent  = JSON.parseObject(s.toString(), SendDentifyingCodeEvent.class);
                    EventBus.getDefault().postSticky(sendDentifyingCodeEvent);
                    System.out.println("发送验证码=" + sendDentifyingCodeEvent);
                }catch(Exception e){
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new SendDentifyingCodeEvent() );
                }
            }
            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new LoginEvent() );
            }


        });
    }
    // 登陆接口
    public static void login(String account,String passwd,Context context){
        String url = String.format(HTTP_NOWUSER, "public/user?at=login");;
        RequestParams params = new RequestParams();
        params.add("account",account);
        params.add("passwd",passwd);

        client.get(context, url, params, new TextHttpResponseHandler() {
            @Override
            public void onSuccess(int i, Header[] headers, String s) {
                try {
                    LoginEvent loginEvent = JSON.parseObject(s.toString(), LoginEvent.class);
                    System.out.println("登入接口=" + loginEvent);
                    EventBus.getDefault().postSticky(loginEvent);
                } catch (Exception e) {
                    L.e("登录login接口异常");
                    e.printStackTrace();
                    EventBus.getDefault().postSticky(new LoginEvent());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, String s, Throwable throwable) {
                System.out.println("网络连接失败=" + s);
                EventBus.getDefault().postSticky(new LoginEvent("连接失败"));
            }


        });
    }

}
